package kr.moiba.commonCd.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import kr.moiba.commonCd.dao.CommonCdDao;
import kr.moiba.commonCd.domain.CommonCd;
import kr.moiba.commonCd.service.CommonCdSvc;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Lee Youngho
 *
 */

@Service
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT ,rollbackFor = {Exception.class} ,readOnly = false)
public class CommonCdSvcImpl implements CommonCdSvc {

	@Autowired
	CommonCdDao commonCdDao;
	
	public CommonCdSvcImpl() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public List<CommonCd> findbyListHeader(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		return (List<CommonCd>) (commonCdDao.SelectListHeader(condition));
	}

	public Map<String, Object> findbyListPagingHeader(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("commonCdHeaderList", (List<CommonCd>) (commonCdDao.SelectListHeader(condition)));
		resultMap.put("commonCdHeaderListTotalCnt", (Integer) (commonCdDao.SelectListTotalCntHeader(condition)));
		
		return resultMap;
	}

	@Override
	public CommonCd findbyHeader(Integer idx) throws Exception {
		// TODO Auto-generated method stub
		return commonCdDao.selectHeader(idx);
	}

	@Override
	public CommonCd addHeader(CommonCd commonCd) throws Exception {
		// TODO Auto-generated method stub
		CommonCd result = commonCdDao.insertHeader(commonCd);
		
		return result;
	}

	@Override
	public CommonCd modifyHeader(CommonCd commonCd) throws Exception {
		// TODO Auto-generated method stub
		return commonCdDao.updateHeader(commonCd);
	}

	@Override
	public int removeHeader(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		return commonCdDao.deleteHeader(condition);
	}
	
	@Override
	public List<CommonCd> findbyListData(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		return (List<CommonCd>) (commonCdDao.SelectListData(condition));
	}

	public Map<String, Object> findbyListPagingData(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("commonCdDataList", (List<CommonCd>) (commonCdDao.SelectListData(condition)));
		resultMap.put("commonCdDataListTotalCnt", (Integer) (commonCdDao.SelectListTotalCntData(condition)));
		
		return resultMap;
	}

	@Override
	public CommonCd findbyData(Integer idx) throws Exception {
		// TODO Auto-generated method stub
		return commonCdDao.selectData(idx);
	}

	@Override
	public CommonCd addData(CommonCd commonCd) throws Exception {
		// TODO Auto-generated method stub
		CommonCd result = commonCdDao.insertData(commonCd);
		
		return result;
	}

	@Override
	public CommonCd modifyData(CommonCd commonCd) throws Exception {
		// TODO Auto-generated method stub
		return commonCdDao.updateData(commonCd);
	}

	@Override
	public int removeData(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		return commonCdDao.deleteData(condition);
	}
	
	@Override
	public String findbyChkDupl(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		
		String result = "true";
		Integer cnt = (Integer) (commonCdDao.SelectListTotalCntData(condition));
		if(cnt != null && cnt == 0){
			result = "false";
		}
		
		return result;
	}

}